package cn.com.css.taxInspection.common.job.task;



import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import cn.com.css.taxInspection.common.constants.Constants;
import cn.com.css.taxInspection.gt3.entity.DmQxSwrysfEntity;
import cn.com.css.taxInspection.gt3.service.DmQxSwrysfService;
import cn.com.css.taxInspection.gt3.service.JcLsfxMxService;
import cn.com.css.taxInspection.gt3.service.JcSjlService;
import cn.com.css.taxInspection.system.entity.SysUser;
import cn.com.css.taxInspection.system.mapper.SysUserMapper;
import cn.com.css.taxInspection.system.service.UserService;
import cn.com.css.taxInspection.util.TsBqUtils;
import cn.com.css.taxInspection.workflow.entity.WorkflowInspectionHearEntity;
import cn.com.css.taxInspection.workflow.entity.WorkflowLogEntity;
import cn.com.css.taxInspection.workflow.service.WorkflowInspectionHearService;
import cn.com.css.taxInspection.workflow.service.WorkflowLogService;
import cn.com.css.taxInspection.workrisk.entity.WorkriskRisk1Entity;
import cn.com.css.taxInspection.workrisk.service.WorkriskControlService;
import cn.com.css.taxInspection.workrisk.service.WorkriskRisk1Service;

/**
 * 每天下午3点提示还未记录工作日志的检查人员完成日志录入。
 *
 * @author shaochangyang
 * @version V1.0
 * @date 2020年3月18日
 */
@Component("risk1Task3")
public class Risk1Task3 {
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	@Resource
	private WorkflowInspectionHearService workflowInspectionHearService;
	
	@Resource
	private WorkriskRisk1Service workriskRisk1Service;
	
	@Resource
	private WorkriskControlService workriskControlService;
	
	@Resource
	private WorkflowLogService workflowLogService;
	
	@Resource
	private JcLsfxMxService jcLsfxMxService;
	
	@Resource
	private UserService userService;
	
	@Resource
	private DmQxSwrysfService dmQxSwrysfService;
	
	public void run(String params) {
		
		Date date = new Date(); 
		List<SysUser> list = userService.list();
		
		for (SysUser sysUser : list) {
			
			String id = sysUser.getId();
			LambdaQueryWrapper<WorkflowLogEntity> queryWrapper = Wrappers.lambdaQuery();

			queryWrapper.eq(WorkflowLogEntity::getCreateId, id);
			queryWrapper.eq(WorkflowLogEntity::getCreateTime, date);
			
			List<WorkflowLogEntity> _listWorkflowLog = workflowLogService.list(queryWrapper);
			if(TsBqUtils.isNull(_listWorkflowLog)){
				
				WorkriskRisk1Entity workriskRisk1Entity = new WorkriskRisk1Entity();
				
				workriskRisk1Entity.setId(TsBqUtils.getUUID());
				workriskRisk1Entity.setRelevance(id);

				// workriskRisk1Entity.setStateCode(stateCode);
				// workriskRisk1Entity.setStateName();
				workriskRisk1Entity.setRiskType("3");
				workriskRisk1Entity.setRiskName("提醒");
				workriskRisk1Entity.setRiskMan1(id);
				workriskRisk1Entity.setDetails("每天下午3点提示还未记录工作日志的检查人员完成日志录入。");
				
				
				LambdaQueryWrapper<DmQxSwrysfEntity> queryWrapper1 = Wrappers.lambdaQuery();

				queryWrapper1.eq(DmQxSwrysfEntity::getSwryDm, id);
				queryWrapper1.eq(DmQxSwrysfEntity::getZsfbz, "Y");
				queryWrapper1.eq(DmQxSwrysfEntity::getYxbz, "Y");
				
				List<DmQxSwrysfEntity> _listDmQxSwrysfEntity = dmQxSwrysfService.list(queryWrapper1);
				
				if(TsBqUtils.isNull(_listDmQxSwrysfEntity)){
					workriskRisk1Entity.setTaxorgcode("");
				}else{
					workriskRisk1Entity.setTaxorgcode(_listDmQxSwrysfEntity.get(0).getSfswjgDm());
				}
				
				workriskRisk1Entity.setDeleted(Constants.DATA_NOT_DELETED);
				workriskRisk1Entity.setCreateTime(new Date());
				workriskRisk1Entity.setCreateId("sysJob");
				
				workriskRisk1Service.save(workriskRisk1Entity);
			}
			
		}
		
	}

}
